package com.haima.sage.bigdata.api.frame.process.impl;

import java.util.List;
import java.util.Map;

import com.haima.sage.bigdata.api.entity.api.Api;
import com.haima.sage.bigdata.api.frame.process.ApiProcess;

public class MultiApiProcess extends ApiProcess {
    private List<ApiProcess> list;

    private MultiApiProcess(Api api, List<ApiProcess> list) {
        super(api);
        this.list = list;
    }

    public List<ApiProcess> getList() {
        return list;
    }

    public static ApiProcess build(Api api, List<ApiProcess> list) {
        return new MultiApiProcess(api, list);
    }

    @Override
    public boolean condition(Map<String, ?> params) {
        return true;
    }

    @Override
    public Object execute(Map<String, ?> params) throws Exception {
        for (ApiProcess service : list) {
            if (service.condition(params)) {
                return service.execute(params);
            }
        }
        return null;
    }
}
